using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class FirstSampleCS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnConnect_Click(object sender, EventArgs e)
    {
        this.WebPartManager1.DisplayMode = WebPartManager.ConnectDisplayMode;
    }
    protected void btnConnect2_Click(object sender, EventArgs e)
    {
        Chapter10CustomControlsCS.ProviderPart prov;
        Chapter10CustomControlsCS.ConsumerPart cons;
        Chapter10CustomControlsCS.BookToAuthorTransform trs = new Chapter10CustomControlsCS.BookToAuthorTransform();
        ConsumerConnectionPointCollection cncp;
        ProviderConnectionPointCollection prcp;
        System.Web.UI.WebControls.WebParts.WebPartTracker wpt;

        prov = (Chapter10CustomControlsCS.ProviderPart)this.znProvider.WebParts["Provider1"];
        cons = (Chapter10CustomControlsCS.ConsumerPart)this.znConsumer.WebParts["Consumer1"];

        prcp = this.WebPartManager1.GetProviderConnectionPoints(prov);
        cncp = this.WebPartManager1.GetConsumerConnectionPoints(cons);

        wpt = new System.Web.UI.WebControls.WebParts.WebPartTracker(prov, prcp[0]);
        if (this.WebPartManager1.CanConnectWebParts(prov, prcp[0], cons, cncp[0]) == true)
        {
            if (wpt.IsCircularConnection == false)
            {
                this.WebPartManager1.ConnectWebParts(prov, prcp[0], cons, cncp[0]);
            }
        }


    }
    protected void btnTransient_Click(object sender, EventArgs e)
    {
        Chapter10CustomControlsCS.ProviderPart fbk;
        Chapter10CustomControlsCS.ConsumerPart cons;
        Chapter10CustomControlsCS.IBookInfo ibk;
        
        fbk = (Chapter10CustomControlsCS.ProviderPart)this.znProvider.WebParts["Provider1"];
        cons = (Chapter10CustomControlsCS.ConsumerPart)this.znConsumer.WebParts["Consumer1"];

        ibk = fbk.IBookInfoProvider();
        cons.IBookInfoConsumer(ibk);        
    }
    protected void btnBreak_Click(object sender, EventArgs e)
    {
        Chapter10CustomControlsVB.ProviderPart prov;
        Chapter10CustomControlsVB.ConsumerPart cons;
        ProviderConnectionPointCollection prcp;
        ConsumerConnectionPointCollection cncp;

        int idx;

        prov = (Chapter10CustomControlsVB.ProviderPart) this.znProvider.WebParts["FindBook1"];
        cons = (Chapter10CustomControlsVB.ConsumerPart) this.znConsumer.WebParts["DisplayAuthor1"];

        prcp = this.WebPartManager1.GetProviderConnectionPoints(prov);
        cncp = this.WebPartManager1.GetConsumerConnectionPoints(cons);

        if (this.WebPartManager1.CanConnectWebParts(prov, prcp[0], cons, cncp[0]) == true)
        {
         this.WebPartManager1.ConnectWebParts(prov, prcp[0], cons, cncp[0]);
         idx = this.WebPartManager1.Connections.Count - 1;
         this.WebPartManager1.Connections[idx].ID = "NewConnection";
        }
          System.Web.UI.WebControls.WebParts.WebPartConnection cn;

        cn = this.WebPartManager1.Connections["NewConnection"];
        this.WebPartManager1.DisconnectWebParts(cn);
        }
}
